AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")

util.PrecacheSound("ambient/atmosphere/thunder1.wav")
util.PrecacheSound("ambient/atmosphere/thunder2.wav")
util.PrecacheSound("ambient/atmosphere/thunder3.wav")
util.PrecacheSound("ambient/atmosphere/thunder4.wav")

function ENT:SpawnFunction( ply, tr )
	if ( !tr.Hit ) then return end
	local SpawnPos = tr.HitPos + tr.HitNormal * 16
	local ent = ents.Create("sent_spaceanon_spore_cloud")
	ent:SetPos( SpawnPos )
	ent:Spawn()
	ent:Activate()
	ent:Start()
	return ent
end

function ENT:Initialize()
	self.Entity:SetModel( "models/Combine_Helicopter/helicopter_bomb01.mdl" )
	self.Entity:PhysicsInit(SOLID_VPHYSICS)
	self.Entity:SetMoveType(MOVETYPE_VPHYSICS)
	self.Entity:SetSolid(SOLID_VPHYSICS)
end

function ENT:Start()
	local spores = math.random(15,30)
	local i = 0
	for i=1, spores do
		local pos = self.Entity:GetPos()+Vector(math.random(-512,512),math.random(-512,512),math.random(-512,512))
		spore = ents.Create("sent_spaceanon_spore")
		spore:SetPos(pos)
		spore:SetAngles(Angle(math.random(0,360),math.random(0,360),math.random(0,360)))
		spore:Spawn()
		while true do
			if spore:IsInWorld() then
				spore:GetPhysicsObject():Sleep()
				break
			end
			pos = self.Entity:GetPos()+Vector(math.random(-512,512),math.random(-512,512),math.random(-512,512))
			spore:SetPos(pos)
		end
	end
	self.Entity:Remove()
end